import java.io.*;
import java.net.*;
import java.awt.*;
import javax.swing.*;

public class Game {

	private GameState state;
	private static NetworkState networkState;
	private static ServerSocket serverSocket;
	public static final int DEFAULT_CHIPS = 1000;
	
	// Constructor for main module
	public Game()
	{
		this.networkState = NetworkState.OFFLINE;
		this.state.deck = new Deck();
	}
	
	public static void main(String[] args)
	{
		WelcomeMenu wMenu = new WelcomeMenu();
		wMenu.setVisible(true);
		
		try
		{
			// Begin main game loop
		    while (true) 
		    {
		    	if(networkState == NetworkState.OFFLINE)
		    	{
		    			    		
		    	}
		    	else if(networkState == NetworkState.SERVER)
		    	{
		    		// wait for events from GUI, clients, new connections
		    		Socket socket = Game.serverSocket.accept();
		    		NetworkConnectionThread task = new NetworkConnectionThread(socket);
		    		new Thread(task).start();
		    	}
		    	else if(networkState == NetworkState.CLIENT)
		    	{
		    		// wait for events from GUI, server	    		
		    	}
		    }
		}
	    catch(IOException ex) 
	    {
		      System.err.println(ex);
		}

		
		SwingUtilities.invokeLater(new Runnable(){
			public void run(){
				new Game().createAndShowGUI();
			}
		});
		
	}
	
	protected static void startServer () 
	{
		try 
		{
			Game.serverSocket = new ServerSocket(8000);
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}
	
	protected static void stopServer() 
	{
		try 
		{
			Game.serverSocket.close();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
		Game.networkState = NetworkState.OFFLINE;
	}
	    	
	protected static void startClient(String x)
	{
		//IP address for server
		
	}
	
	protected static void stopClient()
	{
		
		
	}
	
	public static NetworkState getNetworkState()
	{
		return networkState;
	}
	
	private static class GameState 
	{
		private Deck deck;
		private Player[] players;	
	}
	
	public static String serializeGameState()
	{
		String returnValue = "";
		return returnValue;
	}
	public static void deserializeGameState(String input)
	{
		
	}
	
	
		void createAndShowGUI(){
				
		//test winScreen
		WinScreen win = new WinScreen();
		win.setVisible(true);
		//end test winScreen
			
		Window test = new Window();
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel testp = new JPanel();   
		TopPanel top = new TopPanel();
		BottomPanel bottom = new BottomPanel();
				
		test.getContentPane().add(testp);
		
		testp.add(top);
		testp.add(bottom);
			
		
		test.setPreferredSize(new Dimension(815,675));
		test.pack();
		test.setVisible(true);
		testp.setLayout(new GridLayout(2,0));
		testp.setBackground(Color.black);
		}
		
		
		
		
}
			

		
	

